package com.yutian.springbootvue.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {

	@GetMapping("/info")
    @ResponseBody
    public Map<String, String> getUserInfo(HttpServletRequest httpRequest){
	    String name = null != httpRequest.getAttribute("name") ? httpRequest.getAttribute("name").toString() : "未知用户";
	    Map<String, String> res = new HashMap<>();
	    res.put("name", name);
        return res;
    }

    @PostMapping("/info")
    @ResponseBody
    public Map<String, String> postUserInfo(HttpServletRequest httpRequest){
        String name = null != httpRequest.getAttribute("name") ? httpRequest.getAttribute("name").toString() : "未知用户";
        Map<String, String> res = new HashMap<>();
        res.put("name", name);
        return res;
    }
}
